package com.dameng.work.controller;


import com.alibaba.fastjson.JSON;
import com.dameng.work.pojo.BRAND;
import com.dameng.work.pojo.SHELL;
import com.dameng.work.service.BRANDService;
import com.dameng.work.service.GOODService;
import com.dameng.work.service.SHELLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SynthesizeController {
    @Autowired
    private SHELLService sHELLService;
    @Autowired
    private BRANDService bRANDService;
    @Autowired
    private GOODService gOODService;

//    //初始化数据库
//    @RequestMapping("/Synthesize")
//    @ResponseBody
//    public String initDB() throws IOException {
//
//        //1. 插入4个品牌信息
//
//
//
//    }



    //综合调整
    @RequestMapping("/Synthesize")
    @ResponseBody
    public String SynthesizeDB() throws IOException {

        //1. 生成一位卖家信息
        //2. 随机选取一个品牌
        //3. 生成十万条数据


        SHELL shell = sHELLService.InsertRandomShell();
        BRAND randomBRAND = bRANDService.findRandomBRAND();
        gOODService.batchInsertGOOD(randomBRAND,shell);

        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("state","1" );
        returnMap.put("result",shell);
        return  JSON.toJSONString(returnMap);

    }


    //综合调整
    @RequestMapping("/Synthesize1")
    @ResponseBody
    public String SynthesizeDB1() throws IOException {

        //1. 生成一位卖家信息
        //2. 随机选取一个品牌
        //3. 生成十万条数据

        for (int i = 0; i < 50000; i++) {
            SHELL shell = sHELLService.InsertRandomShell();
            BRAND randomBRAND = bRANDService.findRandomBRAND();
            gOODService.batchInsertGOOD_CUSTOM(randomBRAND,shell);
        }


        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("state","1" );
        returnMap.put("result",null);
        return  JSON.toJSONString(returnMap);

    }
}
